package com.fastCms.manager.mall.controller;

import com.fastCms.business.frame.exception.BusinessException;
import com.fastCms.business.frame.pojo.PageParam;
import com.fastCms.business.frame.pojo.po.IdListPO;
import com.fastCms.business.frame.pojo.po.IdStrPO;
import com.fastCms.business.frame.pojo.po.StatusPO;
import com.fastCms.business.frame.response.ApiResponse;
import com.fastCms.business.mall.manage.ProductManageService;
import com.fastCms.business.mall.pojo.po.*;
import com.fastCms.business.mall.pojo.vo.*;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/product")
@Api(value = "ProductController", tags = "平台端-商品管理")
public class ProductController {

    @Autowired
    private ProductManageService productManageServiceImpl;

    @ApiOperation(value = "新增或编辑商品", notes = "根据商品主键")
    @PostMapping(value = "/saveOrUpdateProduct")
    ApiResponse<String> saveOrUpdateProduct(@RequestBody @Valid ProductInfoEditPO editProductInfoPO)
        throws BusinessException {
        return productManageServiceImpl.saveOrUpdateProduct(editProductInfoPO);
    }

    @ApiOperation(value = "新增或编辑商品其它信息", notes = "根据商品主键")
    @PostMapping(value = "/saveOrUpdateProductOtherInfo")
    public ApiResponse<Boolean> saveOrUpdateProductOtherInfo(@RequestBody @Valid ProductOtherInfoPO productOtherInfoPO) {
        ApiResponse<Boolean> result = productManageServiceImpl.saveOrUpdateProductOtherInfo(productOtherInfoPO);
        return result;
    }

    @ApiOperation(value = "分页展示商品", notes = "分页展示商品")
    @PostMapping(value = "/showPage")
    ApiResponse<ProductPageInfoVO> showPage(@RequestBody PageParam<ProductQueryPO> pageParam) {
        return productManageServiceImpl.showPage(pageParam);
    }

    @ApiOperation(value = "删除商品", notes = "根据商品主键")
    @PostMapping(value = "/deleteProduct")
    ApiResponse<Boolean> deleteProduct(@RequestBody IdStrPO idPO) {
        return productManageServiceImpl.deleteProduct(idPO.getId());
    }

    @ApiOperation(value = "批量商品上下架", notes = "根据商品主键批量商品上下架")
    @PostMapping(value = "/changeProductStoreStatus")
    ApiResponse<Boolean> changeProductStoreStatus(@RequestBody List<StatusPO> statusPOS) {
        return productManageServiceImpl.changeProductStoreStatus(statusPOS);
    }

    @ApiOperation(value = "修改商品库存", notes = "根据商品主键")
    @PostMapping(value = "/changeProductRemainStock")
    ApiResponse<Boolean> changeProductRemainStock(@RequestBody @Valid ProductStockPO productStockPO) {
        return productManageServiceImpl.changeProductRemainStock(productStockPO);
    }

    @ApiOperation(value = "展示商品简易信息", notes = "产品表的基本信息")
    @PostMapping(value = "/showProductBaseInfo/{productId}")
    ApiResponse<ProductVO> showProductBaseInfo(@PathVariable("productId") String productId) {
        return productManageServiceImpl.showProductBaseInfo(productId);
    }

    @ApiOperation(value = "展示商品详情信息", notes = "根据商品主键")
    @PostMapping(value = "/showProductInfo")
    ApiResponse<ProductInfoShowVO> showProductInfo(@RequestBody IdStrPO idPO) {
        return productManageServiceImpl.showProductInfo(idPO.getId());
    }

    @ApiOperation(value = "展示商品sku信息(包含规格)", notes = "根据商品主键-有sku的情况下查询")
    @GetMapping(value = "/showProductSkuInfo/{productId}")
    ApiResponse<ProductSkuInfoShowVO> showProductSkuInfo(@PathVariable("productId") String productId) {
        ApiResponse<ProductSkuInfoShowVO> result = productManageServiceImpl.showProductSkuInfo(productId);
        return result;
    }

    @ApiOperation(value = "商品选择器", notes = "商品选择器")
    @PostMapping(value = "/productSelector")
    ApiResponse<PageInfo<ProductSelectorVO>> productSelector(@RequestBody PageParam<ProductQuerySelectorPO> pageParam) {
        ApiResponse<PageInfo<ProductSelectorVO>> result = productManageServiceImpl.productSelector(pageParam);
        return result;
    }

    @ApiOperation(value = "根据id列表查询商品列表", notes = "根据商品主键列表查询")
    @PostMapping(value = "/showProductList")
    ApiResponse<List<ProductVO>> showProductList(@RequestBody @Valid IdListPO idListPO) {
        ApiResponse<List<ProductVO>> result = productManageServiceImpl.showProductList(idListPO);
        return result;
    }

    @ApiOperation(value = "批量修改商品sku库存", notes = "批量修改商品sku库存")
    @PostMapping(value = "/changeProductSkuStocks")
    ApiResponse<Boolean> changeProductSkuStocks(@RequestBody @Valid ProductSkuStockPO productSkuStockPO) {
        ApiResponse<Boolean> result = productManageServiceImpl.changeProductSkuStocks(productSkuStockPO);
        return result;
    }

    @ApiOperation(value = "展示商品其它相关信息", notes = "根据商品主键")
    @GetMapping(value = "/showProductOtherInfo/{productId}")
    public ApiResponse<ProductOtherInfoVO> showProductOtherInfo(@PathVariable("productId") String productId) {
        ApiResponse<ProductOtherInfoVO> result = productManageServiceImpl.showProductOtherInfo(productId);
        return result;
    }
}
